<template>

    <div>
        <el-row class=" border_bottom" type="flex" justify="start">
            <el-col :span="1">
                <h3> 角色管理</h3>
            </el-col>
        </el-row>


        <el-row>
            <el-table
                    :data="roleList"
                    style="width: 100%">
                <el-table-column
                        prop="roleId"
                        label="角色编号"
                        width="380">
                </el-table-column>
                <el-table-column
                        prop="roleName"
                        label="角色名称"
                        width="380">
                </el-table-column>
                <el-table-column
                        prop="roleDesc"
                        label="权限描述">
                </el-table-column>

                <el-table-column

                        label="操作">
                    <template slot-scope="scope">
                        　　　
                        <el-button v-if="scope.row.roleId==1" type="text" @click="editRole( scope.row.roleId,scope.row.roleName)" disabled>编辑</el-button>

                        <el-button v-else type="text" @click="editRole( scope.row.roleId,scope.row.roleName)">编辑</el-button>
                        　　　
                        　　　
                        <el-button  v-if="scope.row.roleId==1" type="text" @click="delRole( scope.row.roleId)" disabled>删除</el-button>
                        <el-button v-else  type="text" @click="delRole( scope.row.roleId)">删除</el-button>
                        　　
                    </template>

                </el-table-column>
            </el-table>


        </el-row>

    </div>

</template>

<script>
    import ActionType from '../../store/ActionType'
    import router from "@/router";
    import EditRole from './EditRole'

export default {
name: "roleManage",
    data() {
        return {
            memberName: '',
            memberPhone: '',
            roleList: [],
            multipleSelection: [],

        }
    },

    created() {

this.getRole()

    },
    methods:{
    getRole(){
        // 显示角色
        this.$axios.post('/api/admin/getRole').then((res)=>{

            this.roleList=res.data.data
            console.log( this.roleList);
        })
    }
    ,
        editRole(roleId,roleName){
            const currentRole={
                roleId,
                roleName,
            }
            // 保存当前角色
            sessionStorage.setItem('currentRole',JSON.stringify(currentRole))
            // index的子路由


            console.log(router.options.routes[2].children);

            this.$router.push('/EditRole')
        },
        delRole(roleId){
            var that=this
            this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                this.$axios.post('/api/admin/deleteRole?roleIds=',[...[roleId]]).then((res)=>{
                    that.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getRole()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }





    }
}
</script>

<style scoped>
    .border_bottom {

        border-bottom: 1px solid grey;
    }
</style>